<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1.0" />
    <title>小儿推拿</title>
    <%@ include file="/include/datetables.jsp"%>
</head>
<body>
<div class="Baby_Healthy_home">
    <!--左侧-->
    <jsp:include page="/include/menu.jsp" flush="true">
        <jsp:param name="index" value="1"/>
    </jsp:include>
    <!--右侧-->
    <div class="Baby_Healthy_home_right">
        <div class="Baby_Healthy_home_right_top">
            <span class="Baby_Healthy_home_right_top_tit"><i class="icon iconfont icon-menu2"></i>购买商品</span>
        </div>
        <div class="Baby_Healthy_home_billing_right_container container_top">
            <div class="Baby_Healthy_home_billing_right_left">
                <dl class="Baby_Healthy_home_billing_left_dl">
                    <dd class="Baby_Healthy_home_billing_left_dd" flage="false">商品</dd>
                </dl>
            </div>
            <%--无信息页面--%>
            <div class="Baby_Healthy_home_billing_right_center js_nocontent">
                <div class="noticeImg noticeImg15" style="background-size:30%"></div>
            </div>
            <%--卡項列表--%>
            <div class="Baby_Healthy_home_billing_right_center hidden js_cardListgroup">
                    <p class="Baby_Healthy_home_billing_right_center_tit">商品</p>
                    <!-- <div class="home_fast_storage" id="productList"></div> -->
                    <div class="storeelmwrap row zcwrap" id="productList">
                    </div>
            </div>
            <%--右側--%>
            <div class="Baby_Healthy_home_billing_right_right">
                <div class="serachSelect">
                    <select id="searchbox" class="billing_right_right_btn_searchbox" style="width: 80%;">
                        <option value=""></option>
                    </select>
                </div>
                <div class="noticeImg noticeImg15 newNotic"></div>
                <%--消费详情--%>
                <div class="consumeListContains hidden" style="height: 100%"></div>
            </div>
            <!-- 收款弹窗 -->
            <div class="gatheringlist zcwrap hidden">
                <div class="zccard js_paywrap_goods">
                    <h5 class="tit">选择商品支付方式</h5>
                    <div class="zccardelm paystyle">
                        <div class="row" style="margin-bottom:1rem;">
                            <div class="col-lg-4 col-md-4 col-sm-6 pd_hor5">
                                <div class="payelm active" rel="0">
                                    <i class="icon ye"></i>
                                    <span>会员余额</span>
                                </div>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-6 pd_hor5">
                                <div class="payelm" rel="2">
                                    <i class="icon wechat"></i>
                                    <span>微信</span>
                                </div>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-6 pd_hor5">
                                <div class="payelm" rel="1">
                                    <i class="icon alpay"></i>
                                    <span>支付宝</span>
                                </div>
                            </div>

                            <%--<div class="col-lg-4 col-md-4 col-sm-6 pd_hor5">--%>
                            <%--<div class="payelm" rel="5">--%>
                            <%--<i class="icon ca"></i>--%>
                            <%--<span>卡券支付</span>--%>
                            <%--</div>--%>
                            <%--</div>--%>
                        </div>
                        <div class="row" style="margin-bottom:2rem;">
                            <div class="col-lg-4 col-md-4 col-sm-6 pd_hor5">
                                <div class="payelm" rel="3">
                                    <i class="icon money"></i>
                                    <span>现金</span>
                                </div>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-6 pd_hor5">
                                <div class="payelm" rel="4">
                                    <i class="icon ca"></i>
                                    <span>Pos机</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="zccard js_paywrap_other hidden" style="margin-bottom: 1.5rem;">
                    <h5 class="tit">他人代付</h5>
                    <div class="zccardelm js_paywrap_other_new">
                        <div class="row" style="margin-bottom: 10px">
                            <div class="col-sm-4">
                                <label class="form-control-static">代付人手机号：</label>
                            </div>
                            <div class="col-sm-8 font_right row" style="padding-right: 0">
                                <div class="col-sm-12" style="padding-right: 0">
                                    <input type="text" class="form-control js_payOrderPhone">
                                </div>
                            </div>
                        </div>
                        <%--<div class="row">--%>
                            <%--<div class="col-sm-4">--%>
                                <%--<label class="form-control-static"> 验证码：</label>--%>
                            <%--</div>--%>
                            <%--<div class="col-sm-8 font_right row" style="padding-right: 0">--%>
                                <%--<div class="col-sm-8" style="padding-right: 0">--%>
                                    <%--<input type="text" class="form-control js_checkId" style="padding-right: 0" />--%>
                                <%--</div>--%>
                                <%--<div class="col-sm-4" style="padding-right: 0">--%>
                                    <%--<button class="btn btn-sm btn-info js_getCheckBtn" style="width: 100%;">获取验证码</button>--%>
                                <%--</div>--%>
                            <%--</div>--%>
                        <%--</div>--%>
                        <!-- <div class="row">
                            <div class="col-sm-4">
                                &nbsp;
                            </div>
                            <div class="col-sm-8 font_right">
                                <a class="btn btn-sm btn-info js_checkBtn" style="width: 100%;color: #fff;">确定</a>
                            </div>
                        </div> -->
                    </div>
                    <!-- <div class="zccardelm js_paywrap_other_old">
                        <div class="row">
                            <div class="col-sm-4">
                                代付人姓名：
                            </div>
                            <div class="col-sm-8 font_right">
                                <p class="js_payOrderName"></p>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-4">
                               代付人手机号：
                            </div>
                            <div class="col-sm-8 font_right">
                                <p class="js_payOrderPhone"></p>
                            </div>
                        </div>
                    </div> -->
                </div>
                <div class="zccard">
                    <h5 class="tit">消费明细</h5>
                    <div class="zccardelm detaillist">
                        <div class="row littlesumwrap">
                            <div class="col-sm-6">

                            </div>
                            <div class="col-sm-6 font_right">
                                <p class="littlesum">小计：<span data-cost="0">￥0</span></p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="zccard">
                    <h5 class="tit">订单信息</h5>
                    <div class="zccardelm" style="padding: 0 10px;">
                        <div class="row">
                            <div class="col-sm-4">
                                下单时间：
                            </div>
                            <div class="col-sm-8 font_right">
                                <p class="js_createTimetr">2018-01-18  20:33:39</p>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-4">
                                会员姓名：
                            </div>
                            <div class="col-sm-8 font_right">
                                <p class="js_userName">--</p>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-4">
                                会员电话：
                            </div>
                            <div class="col-sm-8 font_right">
                                <p class="js_userPhone">--</p>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-4">
                                会员余额：
                            </div>
                            <div class="col-sm-8 font_right">
                                <p class="js_userAccount font_red">￥ 0</p>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-4">
                                收银员：
                            </div>
                            <div class="col-sm-8 font_right">
                                <p class="js_doctorName">--</p>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-4">
                                门店：
                            </div>
                            <div class="col-sm-8 font_right">
                                <p class="js_subclinicName">--</p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="zccard">
                    <h5 class="tit">订单备注</h5>
                    <div class="zccardelm">
                        <div class="row">
                            <div class="col-sm-12 js_order_desc">
                                --
                            </div> 
                        </div>
                    </div>
                </div>
                <div class="zccard hidden">
                    <h5 class="tit">选择服务支付方式</h5>
                    <div class="zccardelm paystyle">
                        <div class="row" style="margin-bottom:1rem;">
                            
                            <!-- <div class="col-lg-4 col-md-4 col-sm-6 pd_hor5">
                                <div class="payelm" rel="0">
                                    <i class="icon ye"></i>
                                    <span>会员余额</span>
                                </div>
                            </div> -->
                            <div class="col-lg-4 col-md-4 col-sm-6 pd_hor5">
                                 <div class="payelm" rel="4">
                                    <i class="icon ca"></i>
                                    <span>Pos机</span>
                                </div>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-6 pd_hor5">
                                <div class="payelm" rel="2">
                                    <i class="icon wechat"></i>
                                    <span>微信</span>
                                </div>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-6 pd_hor5">
                                <div class="payelm active" rel="3">
                                    <i class="icon money"></i>
                                    <span>现金</span>
                                </div>
                            </div>
                        </div>
                        <div class="row" style="margin-bottom:2rem;">
                            
                            <div class="col-lg-4 col-md-4 col-sm-6 pd_hor5">
                                <div class="payelm" rel="1">
                                    <i class="icon alpay"></i>
                                    <span>支付宝</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="zccard">
                    <div class="zccardelm">
                        <div class="row">
                            <div class="col-sm-12 font_right">
                                <p class="countsum" data-cost="0">应收金额：&nbsp;&nbsp;&nbsp;&nbsp;<span>￥ 0</span></p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
<script src="${pageContext.request.contextPath}/js/homegoods.js"></script>
<script>
    var DocData={
        cashierId:SessionData.userId,//后台登陆用户
        orderId:baseFn.getQueryString('orderId',true),
        userId:baseFn.getQueryString('userId',true),
        userInfo:{
            userId:baseFn.getQueryString('userId',true)
        },
        userName:'',
        userPhone:'',
        doctorId:SessionData.userId,
        subclinicId:SessionData.subclinicId,
        doctorName:SessionData.userName,
        subclinicName:SessionData.subclinicName,
        pay:0,//账单实际支付
        payWays:0,//商品付款方式 0:余额;1:支付宝;2:微信;3:现金;4:Pos机;5:次卡
        payService:0,
        payGoods:0,
        orderDesc:'',
        couponMoney:0,//优惠券优惠
        cost:0,//账单本应付
        otherPay:false,//代付
        initOrder:function(data){
            var _opts={
                createTimetr:baseFn.timestampToTime(Date.parse(new Date())),
                userName:this.userInfo.userName,
                userPhone:this.userInfo.userPhone,
                doctorName:baseFn.notNull(this.doctorName)?this.doctorName:'未知',
                subclinicName:this.subclinicName,
                pay:(baseFn.notNull(data.orderInfo.orderTotalCost)?data.orderInfo.orderTotalCost:0),
                orderDesc:(this.orderDesc==''?'无':this.orderDesc),
                goodsList:((baseFn.notNull(data.goodsList) && data.goodsList.length !=0)?data.goodsList:[]),
                userAccount:DocData.userInfo.userAccount
            }
            var _pDom = $('.gatheringlist')
            _pDom.find('.js_createTimetr').text(_opts.createTimetr)
            _pDom.find('.js_userName').text(_opts.userName)
            _pDom.find('.js_userPhone').text(_opts.userPhone)
            _pDom.find('.js_userAccount').text('￥ ' + _opts.userAccount)
            _pDom.find('.js_doctorName').text(_opts.doctorName)
            _pDom.find('.js_subclinicName').text(_opts.subclinicName)
            _pDom.find('.js_order_desc').text(_opts.orderDesc)
            $('.js_orderDesc').val(_opts.orderDesc)
            // for(var i=0;i<this.cardListDada.length;i++){
            //     var _elm=this.cardListDada[i];
            //     if(_elm.cardId == this.cardId){
            //         this.cardType = _elm.cardType
            //         if(_elm.cardType == 4){
            //             _pDom.find('.detaillist .cardname').text(_elm.cardName)
            //         }else{
            //             _pDom.find('.detaillist .cardname').text(_elm.serviceName+'*'+_elm.cardCount)
            //         }
            //         _pDom.find('.detaillist .money').text(_elm.accountDiscount)
            //     }
            // }
            _pDom.find('.goodselm').remove()
            // var _html2 = ''
            for(var j=0;j<_opts.goodsList.length;j++){
                var _elm = _opts.goodsList[j]
                var _html2 = '<div class="zccardelm row goodselm">\
                            <div class="col-sm-6">'+_elm.goodsName+'</div>\
                            <div class="col-sm-4">\
                                <p class="font_right">x<span class="num">'+_elm.orderNum+'</span></p>\
                            </div>\
                            <div class="col-sm-2 font_right">\
                                <p class="money font_right">￥<span>'+_elm.goodsCost+'</span></p>\
                            </div>\
                        </div>'
                _pDom.find('.detaillist').before(_html2)
            }
            _pDom.find('.littlesumwrap').find('.littlesum span').data('cost',_opts.pay).text('￥ '+_opts.pay)
            _pDom.find('.countsum').find('span').text('￥ '+_opts.pay)
            //他人代付
            if(DocData.otherPay){
                _pDom.find('.js_paywrap_goods').addClass('hidden')
                _pDom.find('.js_paywrap_service').addClass('hidden')
                _pDom.find('.js_paywrap_other').removeClass('hidden')
            }else{
                _pDom.find('.js_paywrap_other').addClass('hidden');
                _pDom.find('.js_paywrap_goods').removeClass('hidden')
            }
        },
        cardURL:'/xrtn-manager/order/gotoOrder?flag=2',
        balanceURL:'/xrtn-manager/order/gotoOrder?flag=2',
        cardListDada:[],
        goodsList:[],
        goodsIds:[],//已选商品id列表
        canRenderOrderList:function(type){
            var _canRender=false
            if(type == 1){
                _canRender = (this.serviceList.length != 0 && $('.js_project_wrap').length == 2 && this.orderData !== '')
            }else if(type == 2){
                _canRender = (this.goodsList.length != 0 && $('.js_project_wrap').length == 1 && this.orderData !== '')
            }
            //判断能否渲染订单并渲染订单列表
            if(_canRender){
                $('.js_project_wrap').find('.tuinaList').remove()
                var _data = this.orderData;
                if(type == 1){
                    for(var i=0;i<_data.serviceList.length;i++){
                        //$('#tuinaList').find('input[value='+_data.serviceList[i].serviceId+']').trigger('click')
                        var _serviceData={
                            value:_data.serviceList[i].serviceId,//服务id或者商品id
                            cardId:_data.serviceList[i].cardId,//卡id
                            name:_data.serviceList[i].serviceName,
                            cost:_data.serviceList[i].serviceCost,
                            num:_data.serviceList[i].cardNumber,
                            useCard:_data.serviceList[i].isUse
                        }
                        this.renderGoodsCar('service',_serviceData)
                        $('#tuinaList').find('input[value='+_data.serviceList[i].serviceId+']').addClass('checkBox_checked')                    
                    }
                    for(var j=0;j<_data.goodsList.length;j++){
                        var _goodSData={
                            value:_data.goodsList[j].goodsId,//服务id或者商品id
                            name:_data.goodsList[j].goodsName,
                            cost:_data.goodsList[j].goodsCost,
                            num:_data.goodsList[j].orderNum
                        }
                        DocData.renderGoodsCar('goods',_goodSData)
                        
                    }
                    sumLit()
                }else if(type == 2){
                    for(var j=0;j<_data.goodsList.length;j++){
                        var _goodSData={
                            value:_data.goodsList[j].goodsId,//服务id或者商品id
                            name:_data.goodsList[j].goodsName,
                            cost:_data.goodsList[j].goodsCost,
                            num:_data.goodsList[j].orderNum
                        }
                        this.renderGoodsCar('goods',_goodSData)
                        $('#productList').find('input[value='+_data.goodsList[j].goodsId+']').addClass('checkBox_checked') 
                    }
                    sumTotal()
                }
            }else{
                return false
            }
        },
        renderGoodsCar:function(type,data){
            //右侧购物车订单列表
            var _data = data
            if(type == 'service'){
                var html='<div class="tuinaList">\
                            <div class="row newAddBtn" style="font-size: 15px;" rel="'+_data.value+'" data-cost="'+_data.cost+'" data-cardid="'+_data.cardId+'">\
                                <div class="col-sm-8 patientDesc font_left texthidden">'+_data.name+'</div>\
                                <div class="col-sm-4 font_right"><span>￥'+_data.cost+'</span><i style="margin-left: 1rem" class="icon iconfont icon-shanchu deleteFr"></i></div>\
                            </div>'
                if(_data.num != 0){
                    html +='<div class="bg_e4 card_wrap">\
                            <div class="row">\
                                <div class="col-sm-8 font_left">\
                                    <span class="patientDesc" style="padding-left: 10px">可使用计次卡</span>\
                                </div>\
                                <div class="col-sm-4 font_right">\
                                    <select class="js_serviceSelCard bg_e4" style="padding-right: 10px;outline: none" value="">\
                                    <option value="0" '+(_data.useCard==0 && 'selected')+'>本次不使用计次卡</option>\
                                    <option value="1" '+(_data.useCard==1 && 'selected')+'>本次使用计次卡</option>\
                                    </select>\
                                </div>\
                            </div>\
                            </div>';
                }
                html +='</div>' 
                var $html=$(html)
                if(_data.useCard==1){
                    $html.find('.newAddBtn').addClass('cardoff')
                } 
                $('#js_cardBox').append($html);
            }else if(type == 'goods'){
                var html2 ='<div class="tuinaList">\
                    <div class="newAddBtn" rel="'+_data.value+'" data-cost="'+_data.cost+'">\
                    <div class="fl" style="max-width:54%">\
                    <span class="patientDesc texthidden" style="display:block;width:100%">'+_data.name+'</span>\
                    </div>\
                    <div class="fr">\
                        <div  class="" style="display: inline-block;margin-right: 1rem;line-height: 0.8rem">\
                            <span class="addNum" rel="0"><i class="icon iconfont icon-jianhao"></i></span><span class="jishuNum">'+_data.num+'</span><span class="addNum" rel="1"><i class="icon iconfont icon-jiahao1"></i></span>\
                        </div>\
                        <span>￥</span>\
                        <span class="moneyNumberTip">'+(_data.cost*100*_data.num/100)+'</span><i class="milk hidden">'+_data.cost+'</i>\
                        <span class="deleteFr"><i style="margin-left: 1rem" class="icon iconfont icon-shanchu"></i></span>\
                    </div>\
                </div>';
                $('#js_cardBox').append(html2);
            }
        },
        initGoodsList:function(initData){//渲染卡项列表
            var _this = this
            baseFn.$get({
                url:baseUrl.init+"selectInitGoodsList",
                data:{state:1},
                calFn:function(dataMsg){
                    for(var i=0;i<dataMsg.length;i++){
                        DocData.goodsList.push(dataMsg[i])
                        var goodsImg = dataMsg[i].goodsImg;
                        var goodsName = dataMsg[i].goodsName;
                        var goodsId = dataMsg[i].goodsId;
                        var goodsCost = dataMsg[i].goodsCost;
                        var goodHtml='<div class="col-sm-3 pd_hor5 js_storeelm">\
                                            <div class="row storecnt">\
                                                <div class="col-sm-10 pd_hor5">\
                                                    <p class="tit">'+goodsName+'</p>\
                                                    <p class="tips">￥<span>'+goodsCost+'</span></p>\
                                                </div>\
                                                <div class="col-sm-2 pd_hor5">\
                                                    <input type="checkbox" value="'+goodsId+'" rel="off" class="checkBox storeelm_checkbox">\
                                                </div>\
                                            </div>\
                                        </div>'
                        $('#productList').append(goodHtml);
                    }
                    if(dataMsg.length != 0){
                        _this.canRenderOrderList(2)
                    }
                }
            })
            // $.get(baseUrl.base+baseUrl.init+'selectInitGoodsList',{state:1},function(res){
            //     if(res.code == 0){
            //         var dataMsg = res.results;
            //         for(var i=0;i<dataMsg.length;i++){
            //             _this.cardListDada.push(dataMsg[i])
            //             var _cardHtml = ''
            //             if(dataMsg[i].cardType == 4){
            //                 _cardHtml='<div class="col-sm-3 pd_hor5 js_storeelm" rel="'+dataMsg[i].cardType+'">\
            //                                 <div class="row storecnt">\
            //                                     <div class="col-sm-10 pd_hor5">\
            //                                         <p class="tit">'+dataMsg[i].cardName+'</p>\
            //                                         <p class="tips">￥<span>'+dataMsg[i].accountDiscount+'</span></p>\
            //                                     </div>\
            //                                     <div class="col-sm-2 pd_hor5">\
            //                                         <input type="checkbox" value="'+dataMsg[i].cardId+'" data-cost="'+dataMsg[i].cardValue+'" rel="off" class="checkBox storeelm_checkbox">\
            //                                     </div>\
            //                                 </div>\
            //                             </div>'
            //             }else if(dataMsg[i].cardType == 5){
            //                 _cardHtml='<div class="col-sm-3 pd_hor5 js_storeelm" rel="'+dataMsg[i].cardType+'">\
            //                                 <div class="row storecnt">\
            //                                     <div class="col-sm-10 pd_hor5">\
            //                                         <p class="tit">'+dataMsg[i].serviceName+'*'+dataMsg[i].cardCount+'</p>\
            //                                         <p class="tips">￥<span>'+dataMsg[i].accountDiscount+'</span></p>\
            //                                     </div>\
            //                                     <div class="col-sm-2 pd_hor5">\
            //                                         <input type="checkbox" value="'+dataMsg[i].cardId+'" data-cost="'+dataMsg[i].cardValue+'" rel="off" class="checkBox storeelm_checkbox">\
            //                                     </div>\
            //                                 </div>\
            //                             </div>'
            //             }
            //             $('#productList').append(_cardHtml); 
            //         }
            //         if(initData){

            //         }
            //     }else{
            //         baseFn.infoDialog(res.msg)
            //     }
            // },'json')
        },
        saveOrder:function(goPay,btnDom){
            var _saveUrl=baseUrl.base+baseUrl.order;
            DocData.payGoods = (DocData.pay-DocData.couponMoney)<0?0:(DocData.pay-DocData.couponMoney);
            var _upData={
                userName:DocData.userInfo.userName,
                userId:DocData.userInfo.userId,
                doctorId: DocData.doctorId,
                subclinicId:DocData.subclinicId,
                orderTotalCost:DocData.cost,
                orderPayCost: DocData.payGoods,
                // couponId:DocData.couponId,//优惠券
                goodsList:[],
                payWay:6,
                orderDesc:$('.js_orderDesc').val()
            }
            this.orderDesc = _upData.orderDesc
            if(DocData.orderId != ''){
                _saveUrl += 'updateOrderInfo',
                    _upData.orderId = DocData.orderId
                    if(baseFn.notNull(DocData.payUserId)){
                        _upData.payUserId=DocData.payUserId
                    }
            }else{
                _saveUrl += 'saveOrderInfo'
            }
            if(DocData.goodsIds.length == 0){
                baseFn.infoDialog('请至少选择一件商品！')
                $(btnDom).attr('rel',0)
                if(orderDialog != ''){
                    orderDialog.close();
                    orderDialog = ''
                }
                return false
            }
            //商品数据
            for(var j=0;j<DocData.goodsIds.length;j++){
                var _ids= DocData.goodsIds[j]
                var _num = Number($('.js_project_wrap[rel=1]').find('.newAddBtn[rel='+_ids+']').find('span.jishuNum').text())
                var _temp = DocData.goodsList.filter(function(val){
                    return val.goodsId == _ids
                })
                if(_temp.length != 0){
                    _temp[0].orderNum = _num
                    _upData.goodsList.push(_temp[0])
                }
            }
            _upData.goodsList = JSON.stringify(_upData.goodsList);
            $.post(_saveUrl,_upData,function(res){
                if(res.code == 0){
                    if(res.results && baseFn.notNull(res.results)){
                        DocData.orderId = res.results
                        $('.otherpay_wrap').removeClass('hidden')
                    }
                    DocData.canPay=true
                    if(goPay){
                        if(btnDom){
                            $(btnDom).attr('rel',0)
                        }
                        $('.consumeListContains .gatheringBtn').trigger('click')
                    }else{
                        if(btnDom){
                            $(btnDom).attr('rel',0)
                        }
                        baseFn.infoDialog('保存成功！')
                    }
                }else{
                    if(btnDom){
                        $(btnDom).attr('rel',0)
                    }
                    baseFn.infoDialog(res.msg)
                }
            },'json').complete(function(){
                if(btnDom){
                    $(btnDom).attr('rel',0)
                }
            })
        },
        cardId:'',
        canPay:false,//订单是否改变
    }
    DocData.initGoodsList();
    //总计
    function sumTotal(){
        var _pay = 0;
        DocData.goodsIds=[]
        if($('#js_cardBox').find('.newAddBtn').length != 0){
            $('.js_orderdesc_wrap').removeClass('hidden')
        }else{
            $('.js_orderdesc_wrap').addClass('hidden')
        }
        $('#js_cardBox').find('.newAddBtn').each(function(i,n){
            DocData.goodsIds.push($(n).attr('rel'))
            var _cardpay = Number($(n).find('.moneyNumberTip').text())
            _pay += _cardpay;
        })
        $('.bottomList_home').find('.likeRed').text(_pay)
        DocData.cost = _pay
        DocData.pay = _pay
        DocData.payGoods = _pay
    }
    //搜索框
    $('.billing_right_right_btn_searchbox').select2({
        placeholder: '请输入会员手机号或姓名',
        language:{
            noResults:function(){return '<span class="font_blue">没有查询到该会员！</span>'},
            searching:function(){return '查询中。。。'}
        },
        allowClear: true,
        ajax: {
            url: baseUrl.base+"user/selectUserList",
            type: "get",
            dataType: 'json',
            data: function (params) {
                return {
                    userPhone: params.term
                }
            },
            processResults: function (data) {
                var dataResult =[];
                var dataItem = data.results.rows;
                for(var i=0;i<dataItem.length;i++){
                    var resultObj = {id:'',text:''};
                    dataItem[i].text = dataItem[i].userName + '-' + baseFn.getHidePhoneStr(dataItem[i].userPhone);
                    dataItem[i].id = dataItem[i].userId;
                    dataResult.push(dataItem[i]);
                }
                return {
                    results:dataResult,
                }
            },
            formatResult: function formatRepo(repo){return repo.text;}, // 函数用来渲染结果
            formatSelection: function formatRepoSelection(repo){return repo.text;} // 函数用于呈现当前的选择
        },
        templateResult:function(state){
            if(!state.loading){
                var _html =  "<p>"+state.userName + "-" + baseFn.getHidePhoneStr(state.userPhone)+"</p>"
                return _html
            }
            
        },
        escapeMarkup: function (markup) {return markup; }, // 自定义格式化防止xss注入
        minimumInputLength: function(e){
            var _val = e.term;
            if(/^[\u4e00-\u9fa5]{1,5}$/.test(_val)){
                return 1
            }else{
                return 3
            }
        }//最少输入多少个字符后开始查询
    });
    $(".billing_right_right_btn_searchbox").on("select2:select",function(e){
        getUserMsgHandle(e.params.data.userId);
    })
    //有订单时候
    if(baseFn.notNull(DocData.orderId)){
        baseFn.$get({
            url:baseUrl.order+'selectOrderInfo',
            data:{orderId:DocData.orderId},
            calFn:function(res){
                DocData.canPay = true
                getUserMsgHandle(res.userInfo.userId);
                DocData.doctorName=(baseFn.notNull(res.orderInfo.cashierName)?res.orderInfo.cashierName:res.orderInfo.doctorName)
                DocData.doctorId=(baseFn.notNull(res.orderInfo.cashierId)?res.orderInfo.cashierId:res.orderInfo.doctorId)
                DocData.subclinicName=res.orderInfo.subclinicName
                DocData.subclinicId=res.orderInfo.subclinicId
                $('.Baby_Healthy_home_billing_left_dd').attr('flage',true);
                $('.gatheringBtn ').trigger('click') 
                DocData.orderDesc= res.orderInfo.orderDesc
                
            }
        })
         
    }
    // // 1.获取用户信息
    // function getUserMsgHandle(userPhone){
    //     $.ajax({
    //         url:baseUrl.base+"user/selectUserList",
    //         type:'get',
    //         data:{
    //             "userPhone":userPhone
    //         },
    //         success:function(data){
    //             if(data.code=="0"){
    //                 var dataResult = data.results.rows;
    //                 $('#searchbox').val(null).trigger('change');
    //                 if(dataResult!=''){
    //                     $('.newNotic>p').hide();//隐藏无数据提示
    //                     for(var i = 0;i<dataResult.length;i++){
    //                         userId = dataResult[i].userId;
    //                         DocData.userId =dataResult[i].userId
    //                         DocData.userName =dataResult[i].userName
    //                         DocData.userPhone =dataResult[i].userPhone
    //                         var gradeName = dataResult[i].dataResult;
    //                         var subclinicName = dataResult[i].subclinicName;
                            
    //                         var userImg = (baseFn.notNull(dataResult[i].userImg)?dataResult[i].userImg: baseUrl.tempHeadImg);
                            
    //                         var userName = dataResult[i].userName;
    //                         var userPhone = dataResult[i].userPhone;
    //                         var gradeName = dataResult[i].gradeName;
    //                         DocData.userName=userName
    //                         var msgHtml = '<div class="listContainsTitle bottomLine">\
    //                                         <span>消费清单</span> <span class="clearAll ">清空页面</span>\
    //                                        </div>\
    //                                        <div class="baseInfo bottomLine zcwrap">\
    //                                             <div class="topHeadPart bottomLine clearfix">\
    //                                                 <div class="headPortrait fl">\
    //                                                     <img src="'+userImg+'">\
    //                                                 </div>\
    //                                                 <div class="fl" style="padding: 0.4rem;padding-bottom: 0;">\
    //                                                     <div style="height: 1.5rem;">'+userName+'</div>\
    //                                                     <div>'+userPhone+'</div>\
    //                                                 </div>\
    //                                             </div>\
    //                                             <div class="newAddBtn saledata">\
    //                                                 <div class="fl">销售人员 <span class="patientDesc doctor">接诊推拿师</span></div>\
    //                                                 <div class="fr">\
    //                                                     <span class="patientDesc sublic">门店</span>\
    //                                                 </div>\
    //                                             </div>\
    //                                             <div class="js_project_wrap" id="js_cardBox" rel="1"></div>\
    //                                             <!--<div class="clearfix eachItem1 hidden js_sumtit" style="line-height: 3rem;">\
    //                                                     <div class="fl">\
    //                                                         <span class="patientDesc">小计金额</span>\
    //                                                     </div>\
    //                                                     <div id="PayNum" class="fr">\
    //                                                         ￥<span>0</span>\
    //                                                     </div>\
    //                                                 </div>\
    //                                                 <div class="js_project_wrap" id="addProductBox_list" rel="2"></div>\
    //                                             </div>-->\
    //                                             <div class="row form-inline" style="margin:auto 0;width:100%">\
    //                                                 <label class="col-sm-3 nopd">订单备注：</label>\
    //                                                 <textarea class="col-sm-9 form-control js_orderDesc" name="bookingDesc" placeholder="请输入预约备注"></textarea>\
    //                                             </div>\
    //                                         </div>\
    //                                         <div class="bottomList_home">\
    //                                             <div class="footerWrapper">\
    //                                             </div>\
    //                                             <div class="payWrapper clearfix">\
    //                                                 <div class="fl">\
    //                                                     待支付： ￥<span class="likeRed">0</span>\
    //                                                 </div>\
    //                                                 <div class="fr">\
    //                                                     <div class="otherpay_wrap hidden">\
    //                                                         <p class="otherpay_wrap_btn">他人代付</p>\
    //                                                     </div>\
    //                                                     <button class="btn btn-sm saveBtnPay btn-rose bg_0 font_7c">保存</button>\
    //                                                     <button class="btn btn-sm gatheringBtn btn-info">收款</button>\
    //                                                 </div>\
    //                                             </div>\
    //                                         </div>';
    //                         $('.consumeListContains').html(msgHtml);
    //                     }
    //                     $('#searchbox').parent('.serachSelect').addClass('hidden').siblings('.consumeListContains').removeClass('hidden').siblings('.noticeImg').addClass('hidden');
    //                 }else{
    //                     $('.Baby_Healthy_home_billing_left_dd').attr('flage',false);
    //                     $('.newNotic').html('<p class="notic_box_img">用户不存在</p>');
    //                 }
    //             }
    //             $($('.Baby_Healthy_home_billing_left_dd:not(".hidden")')[0]).trigger('click')
    //             $('.saledata').find('.doctor').text(DocData.doctorName)
    //             $('.saledata').find('.sublic').text(DocData.subclinicName)
    //             if(DocData.orderId != ''){
    //                 $('.gatheringBtn ').trigger('click')                     
    //             }
    //         }
    //     });
    // }
    // 1.获取用户信息(new)
    function getUserMsgHandle(userId){
        baseFn.$get({
            url:baseUrl.user+'selectUserInfo',
            data:{userId:userId},
            calFn:function(res){
                $('.Baby_Healthy_home_billing_left_dd').attr('flage',true);
                var _userInfo=res.userInfo
                $('#searchbox').val(null).trigger('change');//搜索宝宝框清空
                $('.newNotic>p').hide();//隐藏无数据提示
                DocData.userInfo = _userInfo;
                if(!baseFn.notNull(_userInfo.userImg)){
                    _userInfo.userImg = baseUrl.tempHeadImg
                }
                var msgHtml = '<div class="listContainsTitle bottomLine">\
                                <span>消费清单</span> <span class="clearAll ">清空页面</span>\
                                </div>\
                                <div class="baseInfo bottomLine zcwrap">\
                                    <div class="topHeadPart bottomLine clearfix">\
                                        <div class="headPortrait fl">\
                                            <img src="'+_userInfo.userImg+'">\
                                        </div>\
                                        <div class="fl" style="padding: 0.4rem;padding-bottom: 0;">\
                                            <div style="height: 1.5rem;">'+_userInfo.userName+'</div>\
                                            <div>'+baseFn.getHidePhoneStr(_userInfo.userPhone)+'</div>\
                                        </div>\
                                    </div>\
                                    <div class="newAddBtn saledata">\
                                        <div class="fl">销售人员 <span class="patientDesc doctor">接诊推拿师</span></div>\
                                        <div class="fr">\
                                            <span class="patientDesc sublic">门店</span>\
                                        </div>\
                                    </div>\
                                    <div class="js_project_wrap" id="js_cardBox" rel="1"></div>\
                                    <!--<div class="clearfix eachItem1 hidden js_sumtit" style="line-height: 3rem;">\
                                            <div class="fl">\
                                                <span class="patientDesc">小计金额</span>\
                                            </div>\
                                            <div id="PayNum" class="fr">\
                                                ￥<span>0</span>\
                                            </div>\
                                        </div>\
                                        <div class="js_project_wrap" id="addProductBox_list" rel="2"></div>\
                                    </div>-->\
                                    <div class="row form-inline" style="margin:auto 0;width:100%">\
                                        <label class="col-sm-3 nopd">订单备注：</label>\
                                        <textarea class="col-sm-9 form-control js_orderDesc" name="bookingDesc" placeholder="请输入预约备注"></textarea>\
                                    </div>\
                                </div>\
                                <div class="bottomList_home">\
                                    <div class="footerWrapper">\
                                    </div>\
                                    <div class="payWrapper clearfix">\
                                        <div class="fl">\
                                            待支付： ￥<span class="likeRed">0</span>\
                                        </div>\
                                        <div class="fr">\
                                            <div class="otherpay_wrap hidden">\
                                                <p class="otherpay_wrap_btn">他人代付</p>\
                                            </div>\
                                            <button class="btn btn-sm saveBtnPay btn-rose bg_0 font_7c">保存</button>\
                                            <button class="btn btn-sm gatheringBtn btn-info">收款</button>\
                                        </div>\
                                    </div>\
                                </div>';
                $('.consumeListContains').html(msgHtml);
                if(baseFn.notNull(DocData.userInfo.userId)){
                    $('.otherpay_wrap_btn').removeClass('hidden')
                }else{
                    $('.otherpay_wrap_btn').addClass('hidden')
                }//代付按钮
                $('.serachSelect').addClass('hidden').siblings('.consumeListContains').removeClass('hidden').siblings('.noticeImg').addClass('hidden');  
                $($('.Baby_Healthy_home_billing_left_dd:not(".hidden")')[0]).trigger('click')
                $('.saledata').find('.doctor').text(DocData.doctorName)
                $('.saledata').find('.sublic').text(DocData.subclinicName)    
                if(DocData.orderId != ''){
                    $('.gatheringBtn ').trigger('click')                     
                } 
            },
            comFn:function(){
                // //渲染门店
                // getStoreList()
                // if(DocData.orderId != ''){
                //     $('.gatheringBtn').trigger('click')                       
                // }
            }
        })
    }
    //过滤卡项
    function filterCardList(val){
        $('#productList').find('.js_storeelm').each(function(i,n){
            if($(n).attr('rel') != val){
                $(n).addClass('hidden')
            }else{
                $(n).removeClass('hidden')
            }
        })
    }
    // 选中商品
    $('#productList').on('click','.storeelm_checkbox',function(){
        DocData.canPay = false
        var value = $(this).val();
        if($(this).hasClass('checkBox_checked')){
            $('#js_cardBox>.tuinaList').each(function(i,n){
                var newRel = $(n).find('.newAddBtn').attr('rel');
                if(value==newRel){
                    $(n).remove();
                }
            });
            $(this).removeClass('checkBox_checked');
        }else{
            $(this).addClass('checkBox_checked');
            var _data={
                value:value,//服务id或者商品id
                name:$(this).parents('.storecnt').find('.tit').text(),
                cost:$(this).parents('.storecnt').find('.tips span').text(),
                num:1
            }
            DocData.renderGoodsCar('goods',_data)
        }
        sumTotal()
    })
    // 加减购物车
    $('.Baby_Healthy_home_billing_right_right').on('click','.addNum',function(){
        DocData.canPay = false
        var smallText = $(this).siblings('.jishuNum').text();
        var money =$(this).parent().siblings('.milk').text();
        var newMoney = $(this).parent().siblings('.moneyNumberTip').text();
        if($(this).attr('rel')==1){
            smallText++;
            $(this).siblings('.jishuNum').text(smallText);
            var newMoney =smallText*money;
            $(this).parent().siblings('.moneyNumberTip').text(newMoney);
        }else{
            if(smallText<=1){
                smallText = 1
                return false
            }else{
                smallText--;
            }
            
            var newMoney =newMoney-money;
            $(this).siblings('.jishuNum').text(smallText);
            $(this).parent().siblings('.moneyNumberTip').text(newMoney);
        }
        sumTotal()
        DocData.canPay=false
    })
    // 删除商品/服务
    $('.consumeListContains').on('click','.deleteFr',function(){
        DocData.canPay = false
        var _parent = $(this).parents('.js_project_wrap'),_checkboxRel=$(this).parents('.newAddBtn').attr('rel'),_type = _parent.attr('rel')
        var _pdom=$('#productList')
        // if(_type == 1){
        //     _pdom = $('#tuinaList')
        // }
        _pdom.find('input[value='+_checkboxRel+']').removeClass('checkBox_checked')
        $(this).parents('.tuinaList').remove();
        sumTotal()
        DocData.canPay=false
    })
</script>
</html>